package com.application.module_chat2.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.application.module_chat2.R;
import com.application.module_chat2.bean.uibean.MessageBean;
import com.application.mylibrary.config.Common;
import com.application.mylibrary.utils.DateUtils;
import com.application.mylibrary.utils.ImageLoader.ImageLoader;

/**
 * Created by lixuce on 2019/8/9.
 */
public class MessageAdapter extends BaseQuickAdapter<MessageBean, BaseViewHolder> {


    public MessageAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageBean item) {
        if (helper.getItemViewType() == 1) {
            bindMessage(helper, item);
        }
    }

    private void bindMessage(BaseViewHolder helper, MessageBean item) {
        int stateRes = 0;
        if (item.messageState == Common.MessageState.FAILD) {
            stateRes = R.drawable.ic_item_im_send_failed;
        } else if (item.messageState == Common.MessageState.SENDING) {

        }
        ImageView avatarView = helper.getView(R.id.iv_item_message_avatar);
        ImageLoader.loadHeadPicCircular(mContext, avatarView, item.messageHeadPic);
        helper.setText(R.id.tv_item_message_content, item.messageContent)
                .setText(R.id.tv_item_message_unread, item.messageUnRead)
                .setText(R.id.tv_item_message_name, item.messageName)
                .setText(R.id.tv_item_message_time, DateUtils.formatData(item.messageReceiverTime, mContext.getResources().getString(R.string.rc_yesterday_format)))
                .setGone(R.id.iv_item_message_state, stateRes == 0);
        if (stateRes != 0) {
            helper.setImageResource(R.id.iv_item_message_state, stateRes);
        }
    }
}
